package com.mybatistest.controller;

import com.mybatistest.pojo.Dept;
import com.mybatistest.service.DeptService;
import com.mybatistest.service.impl.DeptServiceImpl;
import com.mybatistest.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RequestMapping("/depts")
@RestController
public class DepController {
    @Autowired
    private DeptService deptService;

    @GetMapping
    public Result deps() {
        log.info("查询全部部门");
        List<Dept> deptList = deptService.list();
        return Result.success(deptList);
    }

    @DeleteMapping(value = "/{id}")
    public Result delete(@PathVariable Integer id){
        log.info("删除部门:{}",id);
        deptService.delete(id);
        return Result.success();
    }

    @PostMapping
    public Result add(@RequestBody Dept dept){
        log.info("新增部门:{}",dept);
        deptService.save(dept);
        return Result.success();
    }

}
